<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name:  Category Model
*
* Author:  Ervin R. Musngi
*
*/

class Item_m extends DataMapperExt
{
	var $table = 'items';
	
	var $has_many	= array(
					'students'	=> array(
						'class'			=> 'Item_m',
						'other_field'	=> 'items',
						'join_self_as'	=> 'item',
						'join_other_as'	=> 'student',
						'join_table'	=> 'student_items'
					)
			);
	
	
	public function insert_item($student_id,$items)
	{
		
		if ( count($items['items'])  > 0 )
		{
			for ( $i = 0; $i < count($items['items']); $i++ )
			{
				$this->db->set('item_id',$items['items'][$i]);
				$this->db->set('amount',$items['amount'][$i]);
				$this->db->set('student_id',$student_id);
				$this->db->insert('student_items');
				
			}
		}
		
	}
	
}